package cn.zh.npro.Activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import java.util.ArrayList;

import cn.zh.npro.Adapter.AcLadapter;
import cn.zh.npro.Item.AcLItem;
import cn.zh.npro.MyApplication;
import cn.zh.npro.R;

public class AcLink extends BaseActivity {
   ImageView ad_back;
   LinearLayout adlin;
   AcLItem acLItem=null;
   ListView aclist;
   AcLadapter acLadapter=null;
   ArrayList<AcLItem> acLItems=null;
   MyApplication mapp;
   TextView clcom;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ac_link);
        mapp= (MyApplication) getApplication();
        acLItems=mapp.getMacLItems();
        initac();
        }

    public void initac(){
        ad_back=findViewById(R.id.ad_back);
        adlin=findViewById(R.id.adlin);
        aclist=findViewById(R.id.aclist);
        clcom=findViewById(R.id.clcom);
        acLadapter=new AcLadapter(AcLink.this,acLItems);
        aclist.setAdapter(acLadapter);
        ad_back.setOnClickListener(this);
        adlin.setOnClickListener(this);
        clcom.setOnClickListener(this);
       }

    @Override
    public void onClick(View view) {
        super.onClick(view);
        int id=view.getId();
        switch (id){
            case R.id.ad_back:
                mapp.getMacLItems().clear();
                finish();
                break;
            case R.id.clcom:
                finish();
                break;
            case R.id.adlin:
                Intent intent=new Intent(AcLink.this,ClinkMan.class);
                startActivityForResult(intent,0);
                break;
              }
            }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        switch (resultCode){
            case 1:
                acLItem= (AcLItem) data.getSerializableExtra("Item");
                acLItems.add(acLItem);
                acLadapter.notifyDataSetChanged();
                break;
          }
         }

    }
